package dmas.lab.schedulers;

public class Event implements Runner{

	private final Task task;
	private final TaskCaller taskCaller;

	public Event(Task task, TaskCaller taskCaller) {
		this.task = task;
		this.taskCaller = taskCaller;
	}

	/***
	 * Runs a specified Task
	 */
	@Override
	public void run() {
		try {
			handleResult(task.runTask());
		} catch (Exception e) {
			taskCaller.handleException(e);
		}
	}
	
	/**
	 * Handles data returned by Task and passes those to caller
	 * @param data
	 */
	private void handleResult(Object data){
		taskCaller.callback(data);
	}

	public Task getTask() {
		return task;
	}

	public TaskCaller getCallback() {
		return taskCaller;
	}
}
